<?php
// 应用公共文件
function curl_get($url,&$httpCode= 0){
    //curl_init()初始化新的会话，返回 cURL 句柄
    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

    //不做证书校验,部署在linux环境下请改为true
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);

    $file_contents = curl_exec($ch);
    $httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    curl_close($ch);
    return $file_contents;
}

function getRandChar($length){
    $str = null;
    $strPol = "ABCDEFGHIJKLNMOPQRSTUVWXYZ1234567890abcdefghijklnmopqrstuvwxyz";
    $max = strlen($strPol) - 1;

    for($i = 0;$i<$length;$i++){
        $str.=$strPol[rand(0,$max)];
    }
    return $str;


}

// 自动加载 extend/WxPay 下类库
function auto_load_class($class = '')
{
    $path = EXTEND."WxPay/WxPay.Api.php";
    include_once($path);
}

function curl_post_raw($url,$rawData){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$rawData);
    curl_setopt(
        $ch,CURLOPT_HTTPHEADER,
        array(
            'Content-Type:text'
        )
    );
    $data = curl_exec($ch);
    curl_close($ch);
    return ($data);
}